package com.lvhr.rpc.filter;

import com.lvhr.rpc.model.RpcRequest;

import java.util.ArrayList;
import java.util.List;

public class SecurityValidationChain {
    private final List<SecurityValidator> validators = new ArrayList<>();

    public SecurityValidationChain addValidator(SecurityValidator validator) {
        validators.add(validator);
        return this;
    }

    public boolean validate(RpcRequest rpcRequest) throws SecurityException {
        for (SecurityValidator validator : validators) {
            if (!validator.validate(rpcRequest)) {
                return false;
            }
        }
        return true;
    }
}
